package com.zhiyou100.api.math_demo;

import java.text.DecimalFormat;
import java.util.Random;
import java.util.Scanner;

public class Demo1 {

    public static void main(String[] args) {
//        test1();
//        Scanner scanner = new Scanner(System.in);
//        System.out.println("请输入两个整数，空格间隔");
//        int a = scanner.nextInt();
//        int b = scanner.nextInt();
//        int max = getMax(a, b);
//        System.out.println("max = " + max);
//        int min = getMin(a, b);
//        System.out.println("min = " + min);
//        System.out.println(Math.abs(-10));
//        int i = rounded_up(59.1);
//        System.out.println("i = " + i);
//        trigonometric(1);
//        exponentiation();
//        testRandom();
//        getEven(2,100);
        testDecimal();
    }

    //数字格式化
    public static void testDecimal(){
        //设定一个格式化对象
        DecimalFormat df = new DecimalFormat("0.0");
        DecimalFormat df2 = new DecimalFormat("#.#");
        DecimalFormat df3 = new DecimalFormat("#.##");
        DecimalFormat df4 = new DecimalFormat("0.00");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个小数");
        double a = scanner.nextDouble();
        System.out.println("0.0 = " + df.format(a));
        System.out.println("#.# = " + df2.format(a));
        System.out.println("#.## = " + df3.format(a));
        System.out.println("0.00 = " + df4.format(a));

    }



    //随机生成一个min-max之间的一个偶数    0,98  + 2
    public static void getEven(int min,int max){
        int v = (int) (Math.random() * (max - min)) + 2;
        if (v % 2 == 0){
            System.out.println("随机偶数是；" + v);
        }else {
            System.out.println("偶数是：" + (v + 1));
        }
    }

    //随机数
    public static void testRandom(){
        Random random = new Random();
        //随机在int范围内获取
        int i = random.nextInt();
        System.out.println("i = " + i);
        int i1 = random.nextInt(50);   // [0,50)
        System.out.println("i1 = " + i1);
        //数学类  有一个随机    随机返回一个小数 [0,1)
        double v = Math.random();
        System.out.println("v = " + v);
        //随机[0,100)
        double v1 = Math.random() * 100;
        System.out.println("v1 = " + v1);
    }




    //指数运算
    public static void exponentiation(){
        double exp = Math.exp(10);   //e的10次幂
        System.out.println("exp = " + exp);
        double pow = Math.pow(4, 3);   //4的3次方
        System.out.println("pow = " + pow);
        double sqrt = Math.sqrt(16);//平方根
        System.out.println("sqrt = " + sqrt);
        double cbrt = Math.cbrt(27);//立方根
        System.out.println("cbrt = " + cbrt);

    }


    //三角函数
    public static void trigonometric(double angle){
        System.out.println("正弦：" + Math.sin(angle));
        System.out.println("余弦：" + Math.cos(angle));
        System.out.println("正切：" + Math.tan(angle));
    }

    //将用户成绩向上取整
    public static int rounded_up(double score){
        //向下取整
        double floor = Math.floor(score);
        System.out.println("floor = " + floor);
        //四舍五入
        long round = Math.round(score);
        System.out.println("round = " + round);
        //返回最接近数据的整数   如果有两个，返回偶数
        double rint = Math.rint(score);
        System.out.println("rint = " + rint);
        //向上取整
        return (int) Math.ceil(score);
    }

    public static int getMin(int a, int b) {
        return Math.min(a, b);
    }

    //根据用户输入的两个整数，获取最大值
    public static int getMax(int a, int b) {
        int max = Math.max(a, b);
        return max;
    }


    public static void test1() {
        double pi = Math.PI;
        System.out.println("pi = " + pi);
        double e = Math.E;
        System.out.println("e = " + e);

    }


}
